#include "packet.h"

#include <anb/common/utils.h>

namespace anb { namespace net {

packet::packet() {
}

packet::~packet() {
}

void packet::deserialize_head(char* segment, int len) {
	id
		= (((unsigned char)segment[0]) <<  8)
		+ (((unsigned char)segment[1])      );
	cmd
		= (((unsigned char)segment[2]) <<  8)
		+ (((unsigned char)segment[3])      );
	unsigned char flags = (unsigned char)segment[4];
	type = (body_type)(flags & flag_body_type_bits);
	response = (flags & flag_response) != 0;
	need_response = (flags & flag_need_response) != 0;
	compress = (flags & flag_compress) != 0;
	err = (error::code)(unsigned char)segment[5];
}

void packet::deserialize_body(char* segment, int len)
{
	m_data.assign(segment, segment + len);
}


} }
